package com.xiang.publicdemo.module1.service.impl;

import com.xiang.publicdemo.module1.service.ITestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TestServiceImpl implements ITestService {

    @Override
    @Async
    public void async(String str) {
        synchronized (str){
            try {
                for (int i = 1;i <= 100;i++){
                    log.info(Thread.currentThread().getName()+"----------异步：>"+i);
                    Thread.sleep(1000l);
                }
                System.out.println( "执行异步任务完毕");
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        System.out.println( Thread.currentThread().getName()+"执行完毕");
    }
}